package com.hatricks.is.exceptionstrace;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * @packageName: com.hatricks.is.exceptionstrace
 * @className: ExceptionTraceTest
 * @author: yanyuhui y568821795@outlook.com
 * @date: 2024-11-07 17:55
 * @description:
 */
public class ExceptionTraceTest {


    public static void main(String[] args) {
        try {
            test01();
        } catch (Exception e) {
            StringBuilder builder = new StringBuilder(256);
            if (e != null) {
                StringWriter writer = new StringWriter(256);
                e.printStackTrace(new PrintWriter(writer));
                builder.append('\n');
                builder.append(writer.toString().trim());
            }
            System.out.println(builder);
        }
    }

    public static void test01() {
        test02();
    }

    public static void test02() {
        try {
            test03();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static void test03() {
        StringBuilder builder = new StringBuilder(256);
        RuntimeException ex = new RuntimeException("xxxxxxxxxxxxxxxxxxxxxxxxxxx");
        if (ex != null) {
            StringWriter writer = new StringWriter(256);
            ex.printStackTrace(new PrintWriter(writer));
            builder.append('\n');
            builder.append(writer.toString().trim());
        }
        throw ex;
    }
}
